package oxi.bigu.persistence;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Component;

import oxi.bigu.business.Caronado;

@Component
public class CaronadoDao {
	
	@PersistenceContext
	private EntityManager entityManager;
	
	@PersistenceUnit
	private EntityManagerFactory factory;
	
	public List<Caronado> selectCaronado() {
		StringBuilder jpql = new StringBuilder();
		jpql.append("select c from ");
		jpql.append("Caronado");
		jpql.append(" c where 1=1");
		TypedQuery<Caronado> query = entityManager.createQuery(jpql.toString(), Caronado.class);
		
		return query.getResultList();
	}

	public void insertCaronado(Caronado caronado) {
		entityManager.persist(caronado);
	}

}
